/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ivanhoe
 */
@Entity
@Table(name = "fletes")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Fletes.findAll", query = "SELECT f FROM Fletes f"),
    @NamedQuery(name = "Fletes.findByIdFlete", query = "SELECT f FROM Fletes f WHERE f.idFlete = :idFlete")})
public class Fletes implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_flete")
    private Integer idFlete;
    @ManyToMany(mappedBy = "fletesCollection")
    private Collection<OrdenesTrabajo> ordenesTrabajoCollection;
    @JoinTable(name = "fletes_has_documentos", joinColumns = {
        @JoinColumn(name = "fletes_id_flete", referencedColumnName = "id_flete")}, inverseJoinColumns = {
        @JoinColumn(name = "documentos_id_documento", referencedColumnName = "id_documento")})
    @ManyToMany
    private Collection<Documentos> documentosCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fletesIdFlete")
    private Collection<Cargas> cargasCollection;
    @JoinColumn(name = "vias_flete_id_via_flete", referencedColumnName = "id_via_flete")
    @ManyToOne(optional = false)
    private ViasFlete viasFleteIdViaFlete;
    @JoinColumn(name = "id_tipo_estado", referencedColumnName = "id_tipo_estado")
    @ManyToOne(optional = false)
    private TiposEstado idTipoEstado;

    public Fletes() {
    }

    public Fletes(Integer idFlete) {
        this.idFlete = idFlete;
    }

    public Integer getIdFlete() {
        return idFlete;
    }

    public void setIdFlete(Integer idFlete) {
        this.idFlete = idFlete;
    }

    @XmlTransient
    public Collection<OrdenesTrabajo> getOrdenesTrabajoCollection() {
        return ordenesTrabajoCollection;
    }

    public void setOrdenesTrabajoCollection(Collection<OrdenesTrabajo> ordenesTrabajoCollection) {
        this.ordenesTrabajoCollection = ordenesTrabajoCollection;
    }

    @XmlTransient
    public Collection<Documentos> getDocumentosCollection() {
        return documentosCollection;
    }

    public void setDocumentosCollection(Collection<Documentos> documentosCollection) {
        this.documentosCollection = documentosCollection;
    }

    @XmlTransient
    public Collection<Cargas> getCargasCollection() {
        return cargasCollection;
    }

    public void setCargasCollection(Collection<Cargas> cargasCollection) {
        this.cargasCollection = cargasCollection;
    }

    public ViasFlete getViasFleteIdViaFlete() {
        return viasFleteIdViaFlete;
    }

    public void setViasFleteIdViaFlete(ViasFlete viasFleteIdViaFlete) {
        this.viasFleteIdViaFlete = viasFleteIdViaFlete;
    }

    public TiposEstado getIdTipoEstado() {
        return idTipoEstado;
    }

    public void setIdTipoEstado(TiposEstado idTipoEstado) {
        this.idTipoEstado = idTipoEstado;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFlete != null ? idFlete.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Fletes)) {
            return false;
        }
        Fletes other = (Fletes) object;
        if ((this.idFlete == null && other.idFlete != null) || (this.idFlete != null && !this.idFlete.equals(other.idFlete))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Fletes[ idFlete=" + idFlete + " ]";
    }
    
}
